Preloading resource dictionaries

In Kanzi you can load resource dictionaries of prefabs you use in your project before your Kanzi application shows them to users. For example, you can create a loading screen that your users see while Kanzi is loading the resource dictionaries of the rest of your application in the background. Once your application loads all the resources you select, it switches from the loading screen to the part of the application you select.

To preload resource dictionaries:

  1. Create a loading screen and place it under Screen > RootPage. Your users see the content of your loading screen while Kanzi loads the resource dictionaries of your application.
    For example, create and image and show it in an Image, or create a Scene which contains an animation that is shown while Kanzi is loading the resources.
  2. Create your Kanzi application in Prefabs and add to the scope of each prefab all the resources used by that prefab. See Using prefabs and Using local and global resources.
  3. In the Project select the RootPage, in the Properties click Add, and add the On Attached trigger.

  4. In the Properties > On Attached trigger click the Add drop-down menu, and select Preload Resources action.
  5. In the Argument Editor:
  6. In the Project select the Screen, in the Triggers click , and add On Preloading of Resources Completed trigger.
  7. In the Triggers click the Add drop-down menu for the On Preloading of Resources Completed trigger, and select Execute Script action.
  8. In the Execute Script window select <Add new script...> to create a new script.
    The Script Editor window opens.
  9. Write and save this script that Kanzi executed when the preloading of resources is completed:
    // Find the RootPage object that is the parent of the Loading screen
    // object you want to replace when preloading of resource is completed.
    var rootPage = node.lookupNode('./RootPage');
    // Find the Loading screen object you want to replace.
    var loadingScreen = node.lookupNode('./RootPage/Loading screen');
    // Instantiate the prefab that contains the content you want to show
    // after you remove the Loading screen object.
    var firstScreen = instantiatePrefab('kzb://<ProjectName>/Prefabs/Viewport 2D', 'First screen');
    // Remove the Loading screen object.
    rootPage.removeChild(loadingScreen);
    // Add the prefab named First screen to the RootPage.
    rootPage.addChild(firstScreen);

See also

Using scripts

Reference for scripting

Using local and global resources

Using external resource dictionaries

Loading resources in parallel

Resource management

Triggers

Using prefabs